#!/bin/sh
result=1
thisdir="$( cd "$( dirname "$0" )" && pwd )"
if [ -n "$REPOS" ]; then
    region=$1
    if [ -z "$region" ]; then
        region=westus
    fi

    if [ ! -f luis.settings.* ]; then
        ($thisdir/build $1 $2)
    fi

    if [ -f luis.settings.* ]; then
        nuget sources add -name "MyGet" -source "https://botbuilder.myget.org/F/botbuilder-v4-dotnet-daily/api/v3/index.json" -verbosity quiet > /dev/null 2>&1
        dotnet run --project $REPOS/BotBuilder-Samples/experimental/generation/runbot/RunBot.csproj --root $thisdir --region $region
        result = $?
    fi
fi

if [ $result != 0 ]; then
    echo "run [region] [LUISAuthoringKey]"
    echo "Set LUISAuthoringKey default with bf config:set:luis --authoringKey=<yourKey>"
    echo "Region defaults to westus."
    echo "In order to use this script you must:"
    echo "1) Setup from https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/generation/docs/get-started.md"
    echo "2) Set the environment variable REPOS to your git repo root."
fi
